﻿namespace RialternativeSample.ViewModels
{
    using System.Collections.ObjectModel;
    using RialternativeSample.Client.Infrastructure;
    using RialternativeSample.Client.Northwind.Interfaces;
    using RialternativeSample.Server.NorthwindService;
    using RialternativeSample.ViewModels.Interfaces;

    public class ProductsViewModel : Notifier, IProductsViewModel
    {
        private ObservableCollection<Products> products;

        public ProductsViewModel(IProductsDataService productsDataService)
        {
            productsDataService.GetProductsAsync(products => this.Products = products);
        }

        // :(
        public bool UserCanSeeCategoriesAndSuppliers
        {
            get
            {
                return WebContext.Current.User.IsInRole("ProductManager") ||
                       WebContext.Current.User.IsInRole("Admin");
            }
        }

        public ObservableCollection<Products> Products
        {
            get
            {
                return this.products;
            }

            private set
            {
                this.products = value;
                this.RaisePropertyChanged(() => this.Products);
            }
        }
    }
}
